<#macro header page_tab="">
<nav class="navbar navbar-inverse">
    <div class="container">
        <div class="navbar-header">
            <button type="button" class="navbar-toggle collapsed" data-toggle="collapse" data-target="#navbar" aria-expanded="false" aria-controls="navbar">
                <span class="sr-only">Toggle navigation</span>
                <span class="icon-bar"></span>
                <span class="icon-bar"></span>
                <span class="icon-bar"></span>
            </button>
            <a class="navbar-brand" style="color:#fff;" href="/">JFinal社区</a>
        </div>
        <div id="navbar" class="navbar-collapse collapse">
            <ul class="nav navbar-nav">
                <li <#if page_tab == 'all'> class="active" </#if>><a href="${ctx_path}/?tab=all">首页</a></li>
                <#list sections as section>
                    <li <#if page_tab == '${section.tab!}'> class="active" </#if>><a href="${ctx_path}/?tab=${section.tab!}">${section.name!}</a></li>
                </#list>
            </ul>
            <form class="navbar-form navbar-left" id="search_form" role="search" method="get" action="${ctx_path}/">
                <div class="form-group">
                    <input type="text" name="q" class="form-control" style="width: 240px" value="${q!}"
                           placeholder="搜索" onkeypress="enterSearch(event)">
                </div>
            </form>
            <script type="text/javascript">
                function enterSearch(e) {
                    var e = e || window.event;
                    if(e.keyCode == 13) {
                        if($("input[name='q']").val() != "") {
                            $("#search_form").submit();
                        }
                    }
                }
            </script>
            <ul class="nav navbar-nav navbar-right">
            <#if session.user??>
                <li><a href="${ctx_path}/user/message/${session.user.id!}">未读消息 <span class="badge" id="badge"></span></a></li>
                <li class="dropdown">
                    <a href="${ctx_path}/user/${session.user.id!}" class="dropdown-toggle" data-toggle="dropdown" role="button" aria-expanded="false">${session.user.nickname!} <span class="caret"></span></a>
                    <ul class="dropdown-menu" role="menu">
                        <#--<li><a href="#">头像设置</a></li>-->
                        <#--<li><a href="#">编辑</a></li>-->
                        <li><a href="${ctx_path}/logout">退出</a></li>
                    </ul>
                </li>
            <#else>
                <li <#if page_tab == 'login'> class="active" </#if>><a href="${ctx_path}/login">登录</a></li>
            </#if>
            </ul>
        </div>
    </div>
</nav>
</#macro>